package org.streets.eis.component.model;

import java.io.Serializable;

/**
 *  icon格式:
 * 		web目录下：以"/"打头，如"/image/aa.gif" 指的是web目录下的image目录中的aa.gif
 * 
 * 		web/WEB-INF/classes目录下(即src目录下编译过去的)：类全限定名+相对路径
 * 			如：
 * 				com.sophia.hr.HomePage/aa.gif 即表示web/WEB-INF/classes/com/sophia/hr/HomePage目录下的aa.gif
 * 				com.sophia.hr.HomePage/res/aa.gif 即表示web/WEB-INF/classes/com/sophia/hr/HomePage/res目录下的aa.gif 
 * 
 * 如果为空或者null,控件或自己采用默认图标
 * 
 */
public class ListItem implements Serializable {

	private static final long serialVersionUID = 1L;

	private String id;
	
	private String text;
	
	private String icon;
	
	public static ListItem empty(){
		return new ListItem("","");
	}
	
	public ListItem(String id,String text){
		this(id,text,null);
	}
	
	public ListItem(String id,String text,String imgUrl){
		this.id = id;
		this.text = text;
		this.setIcon(imgUrl);
	}
	
	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}
	
	public void setText(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getIcon() {
		return icon;
	}
	
	public boolean isNull(){
		return id==null|| id.trim().length() == 0;
	}
	
	@Override
	public int hashCode(){
		return this.id!=null?this.id.hashCode():0;
	}

	@Override
	public boolean equals(Object obj){
		return obj!=null && ListItem.class.isAssignableFrom(obj.getClass()) &&
			(
					(this.id == null && ((ListItem)obj).getId()==null) ||
					(this.id != null && this.id.equals(((ListItem)obj).getId()))
			);
	}
	
	@Override
	public String toString(){
		return text;
	}
}
